//
//	 ______    ______    ______    
//	/\  __ \  /\  ___\  /\  ___\   
//	\ \  __<  \ \  __\_ \ \  __\_ 
//	 \ \_____\ \ \_____\ \ \_____\ 
//	  \/_____/  \/_____/  \/_____/ 
//
//	Powered by BeeFramework
//
//
//  ForgetPassWord.m
//  DingDing
//
//  Created by LHL on 14/12/10.
//  Copyright (c) 2014年 com.gordon. All rights reserved.
//

#import "ForgetPassWord.h"
#import "ForgetPassWord1.h"
#pragma mark -

@interface ForgetPassWord()
{
	//<#@private var#>
}
@end

@implementation ForgetPassWord

SUPPORT_AUTOMATIC_LAYOUT( YES )
SUPPORT_RESOURCE_LOADING( YES )
DEF_OUTLET(BeeUITextField, phonetext)
DEF_MODEL(checkUserExist, icheckUserExist)
- (void)load
{
    self.icheckUserExist = [checkUserExist modelWithObserver:self];
}

- (void)unload
{
    
}

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
    return YES;
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
    return YES;
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return [gestureRecognizer isKindOfClass:UIScreenEdgePanGestureRecognizer.class];
}


#pragma mark - Signal

ON_CREATE_VIEWS( signal )
{
    self.navigationController.interactivePopGestureRecognizer.delegate = self;
    self.title = @"找回密码";
    self.navigationBarShown = YES;
   UIButton *rightbutton = [UIButton buttonWithType:UIButtonTypeCustom];
    rightbutton.frame = CGRectMake(0, 0, 40, 40);
    [rightbutton addTarget:self action:@selector(checkPhoneExist) forControlEvents:UIControlEventTouchUpInside];
    [rightbutton setTitle:@"下一步" forState:0];
    [rightbutton.titleLabel setFont:[UIFont systemFontOfSize:12]];
    [rightbutton setTitleColor:[UIColor whiteColor] forState:0];
    [rightbutton setTitleColor:[UIColor grayColor] forState:UIControlStateDisabled];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:rightbutton];
    self.navigationBarLeft = [UIImage imageNamed:@"back.png"];
}

-(void)checkPhoneExist{
    [self resign];
    if (![self.phonetext.text isTelephone]) {
        [self presentMessageTips:@"请输入11位手机号码"];
    }else{
        self.icheckUserExist.phone = self.phonetext.text;
        [self.icheckUserExist firstPage];
    }
}
ON_SIGNAL3(checkUserExist, RELOADED, SIGNAL){
    [self dismissTips];
    if ([self.icheckUserExist.code isEqualToString:@"200"]) {
        ForgetPassWord1 *pwd = [[ForgetPassWord1 alloc]init];
        pwd.numHint.text = [NSString stringWithFormat:@"验证码已发送至：%@",self.phonetext.text];
        pwd.phone  = self.phonetext.text;
        [self.navigationController pushViewController:pwd animated:YES];
    }else{
        [self presentMessageTips:self.icheckUserExist.msg];
    }
}

ON_SIGNAL3(checkUserExist, RELOADING, SIGNAL){
    [self presentLoadingTips:@"加载中"];
}

ON_DELETE_VIEWS( signal )
{
    
}

ON_LAYOUT_VIEWS( signal )
{
}

ON_WILL_APPEAR( signal )
{
}

ON_DID_APPEAR( signal )
{
}

ON_WILL_DISAPPEAR( signal )
{
}

ON_DID_DISAPPEAR( signal )
{
}

ON_SIGNAL3( BeeUINavigationBar, LEFT_TOUCHED, signal )
{
    [self.navigationController popViewControllerAnimated:YES];
}

ON_SIGNAL3( BeeUINavigationBar, RIGHT_TOUCHED, signal )
{
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    [self resign];
}

-(void)resign{
    for (UIView *t in self.view.subviews) {
        if ([t isKindOfClass:[BeeUITextField class]]) {
            [t resignFirstResponder];
        }
    }
}

@end
